
Following tutorials show how to use SLF4J with either
● default Logback implementation (if no other logging dependencies can be detected in pom.xml)
● Log4j2 implementation (if you include Log4j2 dependencies in pom.xml)
For its internal logging Spring Boot uses
● Jakarta Commons logging (JCL) interface (equivalent to SLF4J)
● Logback implementation (equivalent to Log4J)
Available log levels are : ERROR, WARN, INFO, DEBUG, TRACE.
Selected Log Level will display log lines belonging to that Log Level and those above it.
Default log level is INFO which displays: ERROR, WARN, INFO.
Logging can be configured through application.properties as shown below.
Log Configuration allows you to choose
● Log Level (display log lines belonging to that Log Level and those above it)
● Appender (defines where to log data: Console, File, DatedFile. You can choose multiple destinations)
● Layout (defines how to format log lines: Simple, Pattern, HTML)
Pattern Parameters
Print priority of the logging event
Print message of the logging event
Print last 2 components of Class Path/Name
C
C
o
o
n
n
f
f
i
i
g
g
u
u
r
r
a
a
t
t
i
i
o
o
n
n
t
t
h
h
r
r
o
o
u
u
g
g
h
h
P
P
r
r
o
o
p
p
e
e
r
r
t
t
i
i
e
e
s
s
How Properties are used is very confusing because of following three problems
● each Appender has two references (instead of one)
○ MyAppender1 is used to reference all the lines that belong to the same Appender
○ MyConsoleAppender1Name is used to reference Appender from the Logger (instead of using MyAppender1)
● appenderRef has confusing name, it should be called appenderRefs since it holds references to multiple Appenders
● appenderRef is followed by reference name (like myappender1) even though these names are never used
#APPENDERS
appender.MyAppender1.type = Console
appender.MyAppender1.name = MyConsoleAppender1Name
appender.MyAppender2.type = Console
appender.MyAppender2.name = MyConsoleAppender2Name
appender.MyAppender2.layout.type = PatternLayout
appender.MyAppender2.layout.pattern = MyAppender2: %d %p %c{2} %m %n
#LOGERS
logger.MyLogger1.name = com.ivoronline.springboot_log_log4j_config_xml.controllers
logger.MyLogger1.level = info
logger.MyLogger1.appenderRef.myappender1.ref = MyConsoleAppender1Name
logger.MyLogger1.appenderRef.myappender2.ref = MyConsoleAppender2Name
#DISABLE ROOT LOGGER
rootLogger.level = error